#define _CRT_SECURE_NO_WARNINGS
#include<stdlib.h>
int cmp(void* e1, void* e2)
{

    if (*(int*)e1 > *(int*)e2)
    {
        return 1;
    }
    else if (*(int*)e1 == *(int*)e2)
    {
        return 0;
    }
    else
    {
        return -1;
    }


}
int* singleNumber1(int* nums, int numsSize, int* returnSize)
{
    int* returnNums = (int*)malloc(sizeof(int) * 2);
    qsort(nums, numsSize, sizeof(nums[0]), cmp);
    *returnSize = 2;
    int j = 0;
    int i = 0;
    for (i = 0; i < numsSize; i+=2)
    {
        if (i == numsSize - 1 && j == 1)
        {
            returnNums[j++] = nums[i++];
            return returnNums;
        }
        if (i == numsSize - 2 && nums[i] != nums[i + 1])
        {
            returnNums[j++] = nums[i++];
            returnNums[j++] = nums[i++];
            return returnNums;
        }
        if (nums[i] != nums[i + 1])
        {
            returnNums[j++] = nums[i--];
            if (j == 2)
            {
                return returnNums;
            }
        }


    }

    return returnNums;
}
int* singleNumber(int* nums, int numsSize, int* returnSize)
{
    int sum = 0;
    for (int i = 0; i < numsSize; i++)
    {
        sum ^= nums[i];
    }
    int site = 0;
    while (1)
    {
        if (sum >> site & 1 == 1)
        {
            break;
        }
        else
        {
            site++;
        }

    }
    int type1 = 0;
    int type2 = 0;
    for (int i = 0; i < numsSize; i++)
    {
        if (nums[i] >> site & 1 == 1)
        {
            type1 ^= nums[i];
        }
        else
        {
            type2 ^= nums[i];
        }
    }
    int* returnNums = (int*)malloc(sizeof(int) * 2);
    *returnSize = 2;
    returnNums[0] = type1;
    returnNums[1] = type2;
    return returnNums;
}
int main()
{
    int returnsize = 2;
    int nums[4] = { 0,1,2,2 };
    singleNumber(nums, 4, &returnsize);
    return 0;
}